package cn.xingzhe.monster.user.interfaces.converter;

import cn.xingzhe.monster.user.application.dto.UserDTO;
import cn.xingzhe.monster.user.interfaces.vo.UserVO;
import org.springframework.stereotype.Component;

/**
 * 用户转换器
 * 负责 Interface 层数据转换：DTO → VO
 *
 * @author System
 * @version 1.0.0
 * @since 2024-01-01
 */
@Component
public class UserConverter {

    /**
     * 将 UserDTO 转换为 UserVO
     *
     * @param userDTO 用户DTO
     * @return 用户VO，如果 userDTO 为 null 则返回 null
     */
    public UserVO toVO(UserDTO userDTO) {
        if (userDTO == null) {
            return null;
        }

        return UserVO.builder()
                .id(userDTO.getId())
                .username(userDTO.getUsername())
                .email(userDTO.getEmail())
                .phone(userDTO.getPhone())
                .status(userDTO.getStatus())
                .roles(userDTO.getRoles())
                .permissions(userDTO.getPermissions())
                .createTime(userDTO.getCreateTime())
                .build();
    }
}

